package org.example.listener;

import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands;

public class RedisPublisher {
    private static final RedisClient redisClient = RedisClient.create("redis://localhost:6379");
    private static final StatefulRedisConnection<String, String> connection = redisClient.connectPubSub();

    public static void publishMessage(String channel, String message) {
        RedisPubSubCommands<String, String> sync = (RedisPubSubCommands<String, String>) connection.sync();
        sync.publish(channel, message);
        System.out.println("Published message to channel: " + channel);
    }
}

